package fun.tan90.wx.pay.service;


import fun.tan90.wx.pay.entity.Order;
import fun.tan90.wx.pay.statemachine.OrderEvent;
import fun.tan90.wx.pay.statemachine.OrderStateMachineManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
@RequiredArgsConstructor
public class OrderService {

    final OrderStateMachineManager orderStateMachineManager;

    public boolean pay(String orderCode) {
        Order order = Order.builder().orderCode(orderCode).price(new BigDecimal("1.01")).build();
        return orderStateMachineManager.sendEvent(order, OrderEvent.PAYED);
    }


    public boolean receive(String orderCode) {
        Order order = Order.builder().orderCode(orderCode).price(new BigDecimal("1.01")).build();
        return orderStateMachineManager.sendEvent(order, OrderEvent.RECEIVED);
    }


}
